package com.hmdp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.dto.Result;
import com.hmdp.dto.UserDTO;
import com.hmdp.entity.Shop;
import com.hmdp.entity.ShopComments;
import com.hmdp.mapper.ShopCommentsMapper;
import com.hmdp.service.IShopCommentsService;
import com.hmdp.utils.UserHolder;
import org.springframework.stereotype.Service;

@Service
public class ShopCommentsServiceImpl extends ServiceImpl<ShopCommentsMapper, ShopComments> implements IShopCommentsService {
    @Override
    public Result saveComments(ShopComments shop) {
         // 1.获取登录用户
        UserDTO user = UserHolder.getUser();
        shop.setUserId(user.getId());
        // 2.保存探店笔记
        boolean isSuccess = save(shop);
        if (!isSuccess) {
            return Result.fail("新增评论失败!");
        }
        return Result.ok(shop.getShopId());
    }
}
